const express = require("express");
const router = express.Router();
const relationsController = require("../../controllers/admin/relationsController");

/**
 * @swagger
 * /admin/relations/{enterpriseId}:
 *   get:
 *     summary: 获取指定企业的股权关系
 *     parameters:
 *       - in: path
 *         name: enterpriseId
 *         required: true
 *         description: 企业的唯一标识
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 返回指定企业的股权关系
 *       404:
 *         description: 企业未找到
 */
router.get("/:enterpriseId", relationsController.getEnterpriseRelations);

/**
 * @swagger
 * /admin/relations:
 *   post:
 *     summary: 新增股权关系
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               enterpriseId:
 *                 type: integer
 *                 description: 企业ID
 *               relations:
 *                 type: object
 *                 properties:
 *                   upStreamJSON:
 *                     type: array
 *                     items:
 *                       type: object
 *                       properties:
 *                         legalPerson:
 *                           type: string
 *                         enterpriseName:
 *                           type: string
 *                         proportionEquity:
 *                           type: number
 *                           format: float
 *                   downStreamJSON:
 *                     type: array
 *                     items:
 *                       type: object
 *                       properties:
 *                         legalPerson:
 *                           type: string
 *                         enterpriseName:
 *                           type: string
 *                         proportionEquity:
 *                           type: number
 *                           format: float
 *     responses:
 *       201:
 *         description: 股权关系创建成功
 */
router.post("/", relationsController.createEnterpriseRelation);

/**
 * @swagger
 * /admin/relations:
 *   put:
 *     summary: 更新股权关系
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               id:
 *                 type: integer
 *               enterpriseId:
 *                 type: integer
 *               relations:
 *                 type: object
 *                 properties:
 *                   upStreamJSON:
 *                     type: array
 *                     items:
 *                       type: object
 *                       properties:
 *                         legalPerson:
 *                           type: string
 *                         enterpriseName:
 *                           type: string
 *                         proportionEquity:
 *                           type: number
 *                           format: float
 *                   downStreamJSON:
 *                     type: array
 *                     items:
 *                       type: object
 *                       properties:
 *                         legalPerson:
 *                           type: string
 *                         enterpriseName:
 *                           type: string
 *                         proportionEquity:
 *                           type: number
 *                           format: float
 *     responses:
 *       200:
 *         description: 股权关系更新成功
 *       404:
 *         description: 企业未找到
 */
router.put("/", relationsController.updateEnterpriseRelation);

/**
 * @swagger
 * /admin/relations/{enterpriseId}:
 *   delete:
 *     summary: 删除指定企业的股权关系
 *     parameters:
 *       - in: path
 *         name: enterpriseId
 *         required: true
 *         description: 企业的唯一标识
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 股权关系删除成功
 *       404:
 *         description: 企业未找到
 */
router.delete("/:enterpriseId", relationsController.deleteEnterpriseRelation);

/**
 * @swagger
 * /admin/relations:
 *   get:
 *     summary: 获取所有企业的股权关系列表
 *     responses:
 *       200:
 *         description: 成功返回所有股权关系
 */
router.get("/", relationsController.getAllRelations);


module.exports = router;
